package com.luobu.javaee.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.luobu.javaee.domain.Archive;
import com.luobu.javaee.domain.Document;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface ArchiveMapper extends BaseMapper<Archive> {
    // 设置文档所属文集

    // 根据用户Id和文集名称查询文集编号
    @Select("select archiveId from archive where userId=#{userId} and archiveName=#{archiveName}")
    List<Long> findByUserIdAndArchiveName(Long userId, String archiveName);

    @Update("update document set archiveId=#{archiveId} where userId=#{userId} and docName=#{docName}")
    int updateArchiveIdByUserIdAndDocName(Long userId, String docName, Long archiveId);


    @Select("select * from document where archiveId=#{archiveId}")
    List<Document> findByArchiveId(Long archiveId);

    // check the archive id is existed
    @Select("select archiveId from archive where archiveId=#{archiveId}")
    List<Long> findArchiveIdByArchiveId(Long archiveId);

    @Update("update document set archiveId=-1 where id=#{docId}")
    int updateArchiveIdBydocId(Long docId);

    @Select("select * from archive where userId=#{userId}")
    List<Archive> findByUserId(Long userId);
}
